package com.ob.api;

import com.ob.api.limit.RateLimiterApi;
import com.ob.api.limit.RateLimiterInterceptor;
import com.ob.api.limit.RateLimiterIp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.PostConstruct;

/**
 * @author xzzz
 */
@Slf4j
@ConditionalOnClass(value = RedisTemplate.class)
@Import(ApiMvcConfig.class)
public class ApiConfig {

    @Bean
    public RateLimiterInterceptor apiLimiterInterceptor () {
        return new RateLimiterInterceptor();
    }

    @Bean
    public RateLimiterApi rateLimiterApi () {
        return new RateLimiterApi();
    }

    @Bean
    public RateLimiterIp rateLimiterIp () {
        return new RateLimiterIp();
    }

    @PostConstruct
    public void init() {
        log.info("[OB] [COMMON API MANAGER] 已启用Redis限流");
    }

}
